package com.naml.d_methods;

/**
 * @author marin
 * @version 1.0
 * @date 2025/4/28 20:27
 * @desc 演示守护线程--被设置为守护线程的，当别的线程结束，它就随之结束。
 *       You Jump,I Jump!
 */
@SuppressWarnings("all")
public class ThreadDaemon02 {
    public static void main(String[] args) throws InterruptedException {
        ThreadDaemon daemon = new ThreadDaemon();
        //设置为守护线程
        daemon.setDaemon(true);
        daemon.start();

        for (int i = 1; i <= 20; i++) {
            System.out.println("Lucy劝了: " + i + "次别跳...");
            Thread.sleep(1000);
        }
        System.err.println("Lucy不劝了，跳了船...Jack也跳了...结束...");
    }
}

class ThreadDaemon extends Thread {

    private int count = 0;
    @Override
    public void run() {
        while (true) {
            ++count;
            try {
                System.err.println("Jack想要跳: " + count + "次船的欲望...");
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}